let app = getApp();
let util = require('../../../utils/util')

//Page Object
Page({
    data: {
        systemInfo: app.systemInfo,
        userinfo: {
            name: '',
            iphone: "",
            id: ""
        },
        info: {
            content_name: '',
            integral_count: ''
        }
    },
    Report: function() {
        let _self = this
        let data = {
            sign_name: _self.data.userinfo.name,
            sign_tel: _self.data.userinfo.iphone,
            source: 3,
            exchangeId: _self.data.userinfo.id,
            openId: app.openId
        }
        console.log(_self.data)
        if (_self.data.userinfo.name != '' && _self.data.userinfo.iphone != '') {
            if (_self.data.userinfo.iphone.length == 11 && (/^1(2|3|4|5|6|7|8|9)\d{9}$/.test(_self.data.userinfo.iphone))) {
                util.postRequest('FinanceManage/rest/exchange.do', data, function(res) {
                    console.log(res)
                    if (res.errorcode == 1) {
                        util.alertmodel('积分兑换提示', '兑换成功')
                        wx.switchTab({
                            url: '/packageA/pages/RecordsConsumption/index'
                        });
                    } else {
                        util.alertmodel('积分兑换提示', res.message)
                        wx.switchTab({
                            url: '/pages/integral/index'
                        });
                    }
                })
            } else {
                util.alertmodel('积分兑换提示', '电话格式错误')
            }
        } else {
            util.alertmodel('积分兑换提示', '请正确输入姓名和电话')
        }

    },
    inputname: function(e) {
        console.log(e.detail.value)
        this.setData({
            'userinfo.name': e.detail.value
        })
    },
    inputiphone: function(e) {
        this.setData({
            'userinfo.iphone': e.detail.value
        })
    },
    //options(Object)
    onLoad: function(options) {
        console.log(options)
        this.setData({
            'userinfo.id': options.id,
            'info.content_name': options.content_name,
            'info.integral_count': options.integral_count
        })
    },

    onReady: function() {

    },
    onShow: function() {

    },
    onHide: function() {

    },
    onUnload: function() {

    },
    onPullDownRefresh: function() {

    },
    onReachBottom: function() {

    },
    onShareAppMessage: function() {

    },
    onPageScroll: function() {

    },
    //item(index,pagePath,text)
    onTabItemTap: function(item) {

    }
});